﻿Ext.ns('Ext.am');

Ext.am.CheckGrid = function(config){

	Ext.am.CheckGrid.superclass.constructor.call(this,config);
}

Ext.am.CheckGrid = Ext.extend(Ext.grid.GridPanel,{
	initialized:false,
	layout:'fit',
	loadMask : true,
	cm : new Ext.grid.ColumnModel([new Ext.grid.RowNumberer(), {
			header : '项目ID',
			dataIndex : 'projectcheckrecordid',
			width : 50
		}, {
			header : '项目编号',
			dataIndex : 'projectnumber',
			width : 70
		}, {
			header : '项目名称',
			dataIndex : 'projectname',
			width : 100
		}, {
			header : '主承办单位',
			dataIndex : 'undertakefnit',
			width : 80
		}, {
			header : '验收形式',
			dataIndex : 'checkform',
			width : 80,
			renderer : function(value){
				var a ="";
				if(value == 0){
					a = "会议验收";
				}else 
					a = "材料验收";
				return a;
		}
		}, 
		{
			header : '验收时间',
			dataIndex : 'checkdate',
			width : 80,
			renderer:function(v, cellmeta, record, rowIndex, columnIndex, store){
				var JsonDateValue;
		        if (Ext.isEmpty(v))
		        	return ' ';
		        else if (Ext.isEmpty(v.time))
		        	JsonDateValue = new Date(v);
		        else
		        	JsonDateValue = new Date(v.time);
		        return JsonDateValue.format('Y-m-d');
			}
		},
		{
			header : '项目完成质量等级',
			dataIndex : 'projectfinishqualitylevel',
			width : 100,
			renderer : function(value){
				var a= "";
				switch(value){
				case "0" : a = "不通过";break;
				case "1" : a = "差";break;
				case "2" : a = "中";break;
				case "3" : a = "良";break;
				case "4" : a = "优";break;
				}
				return a;
		}
		},{
			header : '资料归档',
			dataIndex : 'datafiling',
			width : 80,
			renderer : function(value){
				var a="未归档";
				if(value == 1){
					a="已经归档";
				}
				return a;
		}
		},{
			header : '归档日期',
			dataIndex : 'filingdate',
			width : 80,
			renderer:function(v, cellmeta, record, rowIndex, columnIndex, store){
				var JsonDateValue;
		        if (Ext.isEmpty(v))
		        	return ' ';
		        else if (Ext.isEmpty(v.time))
		        	JsonDateValue = new Date(v);
		        else
		        	JsonDateValue = new Date(v.time);
		        return JsonDateValue.format('Y-m-d');
			}
		},{
			header : '归档目录',
			dataIndex : 'filingdirectory',
			width : 80
		},{
			header:'操作',
			dataIndex:'filingdate',
			width:80,
			renderer:function(value, cellmeta, record, rowIndex, columnIndex, store){
			
			var checkdate,filingdate;
	        if (Ext.isEmpty(record.get('checkdate')))
	        	checkdate =' ';
	        else if (Ext.isEmpty(record.get('checkdate').time))
	        {	
	        	checkdate = new Date(record.get('checkdate'));
	        	checkdate.format('Y-m-d');
	        } else {
	        	checkdate = new Date(record.get('checkdate').time);
	        	checkdate.format('Y-m-d');
	        }
	        
	        if (Ext.isEmpty(record.get('filingdate')))
	        	filingdate =' ';
	        else if (Ext.isEmpty(record.get('filingdate').time)){
	        	filingdate = new Date(record.get('filingdate'));
	        	filingdate.format('Y-m-d');
	        }
	        else {
	        	filingdate = new Date(record.get('filingdate').time);
	        	filingdate.format('Y-m-d');
	        }
	        
	        
				
				var brow="cm_operation('"+record.get('projectcheckrecordid')
						+"','"+record.get('projectnumber')
						+"','"+record.get('projectname')
						+"','"+record.get('checkform')
						+"','"+checkdate
						+"','"+record.get('projectfinishqualitylevel')
						+"','"+record.get('datafiling')
						+"','"+filingdate
						+"','"+record.get('filingdirectory')+"');return false;";
				var b = ' <a  onclick="'+brow+'">操作</a>&nbsp;';
				
			return b;
		}
		}
		]),
	store: new CheckGridStore(),
	initComponent:function(){
		this.tbar = [{
			xtype:'label',
			text:'编号:    '
		},{
			xtype:'textfield',
			fieldLabel : '编号查询',
			id:'cm_numbercheck'
			
		},{
			xtype:'label',
			text:'名称：    '
		},{
			xtype:'textfield',
			fieldLabel : '编号查询',
			id:'cm_namecheck'
			
		},{
			xtype:'button',
			text:'查询',
			handler : function(b,e){
				var a = b.findParentBy(function(ct, cmp) { 
					return (ct instanceof Ext.grid.GridPanel) ? true : false; 
					});
				a.store.load({
					params:{
					start:0,
					limit: 30,
					numberQuery : a.getTopToolbar().findById('cm_numbercheck').getValue(),
					nameQuery : a.getTopToolbar().findById('cm_namecheck').getValue()
				}
				});
		}
			
		}];
		this.bbar = new Ext.PagingToolbar({
			pageSize : 20,
			store : this.store,
			displayInfo : true,
			displayMsg : '显示 {0}-{1}条 / 共 {2} 条',
			emptyMsg : "无数据。",
			plugins        : [new Ext.ux.PageSizePlugin()],
			items : ['-']
		});
	Ext.am.CheckGrid.superclass.initComponent.call(this)
	}
})

function cm_operation(id,number,name,form,checkdate,level,filing,filingdate,dir){

	var a = Ext.getCmp('cm_updatewindow');//判断windows是否存在
	if(a == null){ //如果不存在 则new 一个
		a = new Ext.cm.UpdateWindow({
			id:'cm_updatewindow',
			closable : true
		});
	}
	//进行一些必要的赋值
	a.updatePanel.findById(a.id+'projectcheckrecordid').setValue(id);
	a.updatePanel.findById(a.id+'proejectnumber').setValue(number);
	a.updatePanel.findById(a.id+'projectname').setValue(name);
	a.updatePanel.findById(a.id+'checkform').setValue(form);
	a.updatePanel.findById(a.id+'checkdate').setValue(checkdate);
	a.updatePanel.findById(a.id+'projectfinishqualitylevel').setValue(level);
	a.updatePanel.findById(a.id+'datafiling').setValue(filing);
	a.updatePanel.findById(a.id+'filingdate').setValue(filingdate);
	a.updatePanel.findById(a.id+'filingdirectory').setValue(dir);
	
	a.show();
}